package com.woniu.product.controller;


import com.woniu.entity.Result;
import com.woniu.product.pojo.ChargeStation;
import com.woniu.product.entity.dto.FindChargeStationDTO;
import com.woniu.product.entity.dto.UserChargeDTO;
import com.woniu.product.service.IChargeService;
import io.swagger.annotations.Api;
import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.product.entity.ChargePileQuery;
import com.woniu.product.entity.ChargeStationQuery;
import com.woniu.product.entity.ChargePileStatistics;
import com.woniu.product.pojo.ChargePile;
import com.woniu.product.pojo.ChargeStation;
import com.woniu.product.service.IChargePileService;
import com.woniu.product.service.IChargeStationService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 充电站表 前端控制器
 *
 * @author LiFangyu
 * @since 2023-02-20
 */
@RestController
@RequestMapping("/charge")
@Api(tags = "充电控制类")
public class ChargeController {

    @Autowired
    private IChargeService chargeService;
    @Autowired
    private IChargePileService chargePileService;
    @Autowired
    private IChargeStationService chargeStationService;

    @PostMapping("/list/station")
    @ApiOperation("查找可用充电站|按距离显示")
    public Result<List<ChargeStation>> searchStation(@RequestBody FindChargeStationDTO findChargeStationDTO) {
        List<ChargeStation> chargeStations = chargeService.searchStation(findChargeStationDTO);
        return Result.ok(chargeStations);
    }

    @PostMapping("/begin/charge")
    @ApiOperation("用户充电")
    public Result<Object> beginCharge(@RequestBody UserChargeDTO userChargeDTO) {
        return chargeService.beginCharge(userChargeDTO);
    }


    @ApiOperation("新增充电桩")
    @PostMapping("/addChargePile")
    public Result<ChargePile> addChargePile(@RequestBody ChargePile chargePile) {
        chargePileService.addChargePile(chargePile);
        return Result.ok();
    }

    @ApiOperation("删除充电桩")
    @DeleteMapping("/deleteChargePile")
    public Result<ChargePile> deleteChargePile(String id) {
        chargePileService.deleteChargePile(id);
        return Result.ok();
    }

    @ApiOperation("修改充电桩")
    @PutMapping("/updateChargePile")
    public Result<ChargePile> updateChargePile(@RequestBody ChargePile chargePile) {
        chargePileService.updateChargePile(chargePile);
        return Result.ok();
    }

    @ApiOperation("查找充电桩")
    @GetMapping("/queryChargePile")
    public Result<PageResult<ChargePile>> queryChargePile(Integer currentPage,
                                                          Integer pageSize,
                                                          ChargePileQuery chargePileQuery) {
        PageResult<ChargePile> pageResult = chargePileService.queryChargePile(currentPage, pageSize, chargePileQuery);
        return Result.ok(pageResult);
    }

    @ApiOperation("新增充电站")
    @PostMapping("/addChargeStation")
    public Result<ChargeStation> addChargeStation(@RequestBody ChargeStation chargeStation) {
        chargeStationService.addChargeStation(chargeStation);
        return Result.ok();
    }

    @ApiOperation("删除充电站")
    @DeleteMapping("/deleteChargeStation")
    public Result<ChargeStation> deleteChargeStation(String id) {
        chargeStationService.deleteChargeStation(id);
        return Result.ok();
    }

    @ApiOperation("修改充电站")
    @PutMapping("/updateChargeStation")
    public Result<ChargeStation> updateChargeStation(@RequestBody ChargeStation chargeStation) {
        chargeStationService.updateChargePile(chargeStation);
        return Result.ok();
    }

    @ApiOperation("查找充电站")
    @GetMapping("/queryChargeStation")
    public Result<PageResult<ChargeStation>> queryChargeStation(Integer currentPage,
                                                                Integer pageSize,
                                                                ChargeStationQuery chargeStationQuery) {
        PageResult<ChargeStation> pageResult = chargeStationService.queryChargeStation(currentPage, pageSize, chargeStationQuery);
        return Result.ok(pageResult);
    }

    @ApiOperation("充电桩统计")
    @GetMapping("/queryChargePileStatistics")
    public Result<PageResult<ChargePileStatistics>> queryChargePileStatistics(Integer currentPage,
                                                                              Integer pageSize,
                                                                              ChargePileQuery chargePileQuery) {
        PageResult<ChargePileStatistics> pageResult = chargePileService.queryChargePileStatistics(currentPage, pageSize, chargePileQuery);

        return Result.ok(pageResult);
    }
}
